package com.example.myapplication.ui.viewmodel

import androidx.room.*
import com.example.myapplication.ui.upload.FileUploadBean

@Dao
abstract class UploadDao {

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    abstract fun insert(bean : FileUploadBean)

    @Query("SELECT * FROM file_upload_table WHERE uuid=:uuid limit 1")
    abstract fun find_UUID(uuid: String): FileUploadBean?

    @Query("UPDATE OR ABORT file_upload_table SET uploadId = :uploadId , updateAt =:updateAt  WHERE `uuid` = :uuid ")
    abstract fun update_uploadId_UpdateAt(uuid: String, uploadId: String, updateAt: Long = System.currentTimeMillis())

    // 事务 open 很重要
    @Transaction
    open fun updateAndGet( uuid: String, uploadId: String): FileUploadBean?{
        update_uploadId_UpdateAt(uuid , uploadId)
        return find_UUID(uuid)
    }
}